time: 2021.3


# -*- coding: utf-8 -*-
# @Time    : 2021/5/17 16:51
# @Author  : luogan
# @Email   : 468640092@qq.com
# @File    : 回合制对战游戏.py
# @Software: PyCharm.

# 回合制对战游戏
# 创建角色：，名字、性别、血量、装备
# 创建房间：角色可加入房间 房间内的人可以互打 房间上限2人
# 装备-防弹衣 血量默认100 正常被攻击-10滴血量 有防弹衣-5滴血

import time
class player():
    blood = 100

    def __init__(self, name, sex, equip):  # 定义一个初始化方法设定玩家的属性

        self.name = name
        self.sex = sex
        self.equip = equip

    def fire(self, player):

        if player.equip != 'fangdanyi':

            print(f'[%s]还没有防弹衣......即将承受剧烈打击!' % player.name)

            player.blood -= 10

            print(f'遭到沉重打击......血量急剧下降,当前血量剩余[%s]大喊一声--长枪依在!' % player.blood)


        else:

            print('[%s]有防弹衣......即将承受轻微打击!' % player.name)

            player.blood -= 5

            print('遭到轻微打击......血量轻微减少,当前血量剩余[%s]大喊一声--金刚不坏之身!' % player.blood)


class Room():
    def __init__(self, name):
        self.name = name
        self.member_list = []

    def add_member(self, player):
            if len(self.member_list) < 2:
                self.member_list.append(player)
                print(f"{player.name}成功加入{self.name}房间")
            elif len(self.member_list) > 2:
                print('人数已满')
            else:
                print(f"{player.name}已加入{player.room.name}房间")



print('玩家solo战即将开始,让我们拭目以待!'.center(80, '*'))

a = player('luo', 'nv', 'fangdanyi')
b = player('li', 'nan', '')
room1 = Room("room1")
room1.add_member(a)

while 1:
    if a.blood <= 0:
        print(f"{b.name}赢了")
        break
    if b.blood <= 0:
        print(f"{a.name}赢了")
        break
    time.sleep(1)
    a.fire(b)
    time.sleep(1)
    b.fire(a)
